var a = require("../../../@babel/runtime/helpers/toConsumableArray"), t = getApp(), o = 1;

Page({
    data: {
        title: "搜索",
        inputs: "",
        amout: !1,
        loading: !1,
        allLoaded: !0,
        topStatus: "",
        bottomStatus: "",
        wrapperHeight: 0,
        order_by: "",
        order_field: "",
        datas: [],
        totalGoodsNum: 0,
        pushData: ""
    },
    onLoad: function(a) {
        a.coupon && this.setData({
            coupon: a.coupon
        }), a.id && this.setData({
            id: a.id
        }), a.shop_id && this.setData({
            shop_id: a.shop_id
        }), this.gotoSearch(o);
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        var a;
        this.data.current_page >= this.data.last_page || (console.log(this.data.page), this.data.page ? a = Number(this.data.page) + 1 : (a = 2, 
        this.setData({
            page: a
        })), this.gotoSearch(a));
    },
    onShareAppMessage: function() {},
    gotoSearch: function() {
        var o = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 1, e = this, s = t.getNetAddresss("plugin.micro.frontend.controllers.MicroShop.goods.search-goods");
        s += "&search[keyword]=" + this.data.inputs, s += "&page=" + o, s += "&search[category]=" + this.data.id, 
        s += "&order_field=" + this.data.order_field, s += "&order_by=" + this.data.order_by, 
        s += "&search[couponid]=" + this.data.coupon, s += "&shop_id=" + this.data.shop_id, 
        t._getNetWork({
            url: s,
            success: function(t) {
                var o = t.data;
                if (1 == o.result) {
                    if (e.setData({
                        loading: !1,
                        allLoaded: !1
                    }), o.data.data.length <= 0) return void e.setData({
                        loading: !0,
                        allLoaded: !0
                    });
                    if (o.data.current_page > o.data.last_page) return void e.setData({
                        loading: !0,
                        allLoaded: !0
                    });
                    var s = e.data.datas;
                    if (s.push.apply(s, a(o.data.data)), e.setData({
                        datas: s,
                        current_page: o.data.current_page,
                        last_page: o.data.last_page
                    }), o.data.data.length < 20) return void e.setData({
                        loading: !0,
                        allLoaded: !0
                    });
                }
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    changeTotal: function(a) {
        var t = this, o = a.detail, e = 0;
        this.setData({
            pushData: ""
        }), o.map(function(a) {
            a.value && (e++, t.setData({
                pushData: t.data.pushData + a.id + ","
            }));
        }), this.setData({
            totalGoodsNum: e
        });
    },
    search: function() {
        o = 1, this.setData({
            datas: [],
            page: 1
        }), this.gotoSearch(o, !1);
    },
    inpbtn: function(a) {
        var t = a.detail.value;
        this.setData({
            inputs: t
        });
    },
    pushFn: function() {
        var a = this;
        if (t._isTextEmpty(this.data.pushData) || 0 == this.data.pushData.length) wx.showToast({
            icon: "none",
            title: "请选择商品",
            duration: 1500
        }); else {
            var o = t.getNetAddresss("plugin.micro.frontend.controllers.MicroShop.set-goods");
            o += "&goods_ids=" + this.data.pushData, t._getNetWork({
                url: o,
                success: function(t) {
                    1 == t.data.result && wx.reLaunch({
                        url: "/packageC/microshop/microShop_home/microShop_home?shop_id=" + a.data.shop_id
                    });
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        }
    }
});